﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		event.setArg("pageTitle", "教学质量评价");
		
		/* 学期相关信息 */
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		termDateStart = event.getArg("DateStart");
		
		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();


		/* 刷新当前学生需要的评教数据 */
		transaction{
			
			/* 当前时间戳 */
			currentTimeStamp = datetimeAdvice.getCurrentDatetimeString();
			
			/* 追加评教状态数据 */
			sql = "INSERT INTO t_student_evaluate 
					( scc_id, state, date_create, date_lastupdate ) 
					SELECT 
					a.scc_id, 'NO' state, :ts date_create, :ts date_lastupdate 
					FROM t_student_course a 
					WHERE 
						a.term_id = :termId 
						AND 
						a.stu_id = :studentId 
						AND 
						substr(a.choose_prop, 2, 1) = '1' 
						AND 
						NOT EXISTS ( 
							SELECT 1 FROM t_student_evaluate b 
							WHERE 
								a.scc_id = b.scc_id 
						) 
						AND 
						EXISTS ( 
							SELECT 1 FROM t_course_evaluate c 
							WHERE 
								c.cid = a.cid 
						) ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="ts", value=currentTimeStamp, cfsqltype="cf_sql_char" );

			queryObj.execute( sql=sql ).getResult();

		}
		
		
		
		/* 网上评教相关设置 */
		dateStart = event.getArg("EVALSYS.STU.DateStart");
		dateEnd = event.getArg("EVALSYS.STU.DateEnd");
		//stuMarkView = event.getArg("EVALSYS.STU.DisableMarkView");
		
		/* 当前日期 */
		dateNow = datetimeAdvice.getCurrentDateString();
		
		/* 计算当前教学周 */
		currentWeek = mathAdvice.convertTaskWeek( termDateStart, dateNow );
		
		/* 是否在可评教时间 */
		if ( dateNow GTE dateStart AND dateNow LTE dateEnd ) {

			/* 读取当前需要评教的数据 */
			sql = "SELECT 
					t_student_evaluate.scc_id, 
					t_student_evaluate.state, 
					t_evaluate_system.es_id, 
					t_evaluate_system.es_model, 
					mv_running_task.institute_short, 
					mv_running_task.task_type, 
					mv_running_task.task_id, 
					mv_running_task.course_code, 
					mv_running_task.course_name, 
					mv_running_task.course_credit, 
					mv_running_task.task_week, 
					mv_running_task.tch_name, 
					mv_running_task.tch_name_sec, 
					mv_running_task.tch_name_ace 
					FROM t_student_evaluate 
					INNER JOIN t_student_course ON t_student_evaluate.scc_id = t_student_course.scc_id 
					INNER JOIN mv_running_task ON mv_running_task.task_id = t_student_course.task_id 
					INNER JOIN t_course_evaluate ON t_course_evaluate.cid = mv_running_task.cid 
					INNER JOIN t_evaluate_system ON t_evaluate_system.es_id = t_course_evaluate.es_id 
					WHERE 
						t_student_course.term_id = :termId 
						AND 
						t_student_course.stu_id = :studentId 
						AND 
						( 
						t_student_evaluate.state = 'NO' OR t_student_evaluate.state = 'C1' OR t_student_evaluate.state = 'C2' 
						) 
					ORDER BY institute_short, course_name ";
		
			queryObj = new Query( datasource=application.dnsSlave );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
	
			rs_course = queryObj.execute( sql=sql ).getResult();	
			
		}
		
		/* 意见及回复 */
		sql = "SELECT 
				a.msg_id, 
				a.suggest, a.suggest_date, 
				a.reply, a.reply_date 
				FROM t_evaluate_comment a 
				WHERE 
					a.stu_id = :studentId 
					AND 
					a.term_id = :termId 
				ORDER BY a.suggest_date DESC";
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
	
		rs_comment = queryObj.execute( sql=sql ).getResult();
		
		
		/* 判断当前标签显示 */
		currentTab = event.getArg("TabID", "labQuestionnaire");
		
		passArgs = structNew();

	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">

			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 application"></i>教学质量评价
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labQuestionnaire">class="active"</cfif> id="labQuestionnaire" tabTarget="Questionnaire">网上评教的课程</span>
						<span <cfif currentTab eq "labTalking">class="active"</cfif> id="labTalking" tabTarget="Talking">师生互动</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Questionnaire" class="tabContent">
					
					<div class="noticeBlock">
						<h3>教学质量评价学生问卷</h3>
						<p><span class="img icon16x16 message"></span>下面列出的是目前与您相关的课程教学质量调查问卷, 请花费少许时间, 帮助我们完成教学质量督察.</p>
						<hr/>
					</div>
					
					<cfset writeLog( text='------------------' ) /> 
					
					<cfset writeLog( text=dateNow ) /> 
					<cfset writeLog( text=dateStart ) /> 
					<cfset writeLog( text=dateEnd ) /> 
					
					<cfif dateNow GTE dateStart AND dateNow LTE dateEnd >
						
							<!--- 在网上评教时间范围内 --->
							
							<cfif rs_course.recordCount >
								
								<div class="systemNotice">
									<p><span class="img icon16x16 info"></span>各位同学，此处提交的各类评分、问卷及建议均为匿名信息，请根据实际情况对任课教师的教学工作作出客观、公正的评价。</p>
								</div>
								
								<table class="UIEditable">
									<thead>
										<tr>
											<td width="20"></td>
											<td width="60">任课单位</td>
											<td>课程</td>
											<td width="40">学分</td>
											<td width="50">周次</td>
											<td width="20"></td>
										</tr>
									</thead>
									<tbody>
										<cfset row = 0 />
										<cfloop query="rs_course">
											
											<cfset row++ />
											
											<!--- 教师列表 --->
											<cfset teacherList = rs_course.tch_name />
											<cfif not listFind( teacherList, rs_course.tch_name_sec, "/" ) >
												<cfset teacherList = listAppend( teacherList, rs_course.tch_name_sec, "/" ) />
											</cfif>
											<cfif not listFind( teacherList, rs_course.tch_name_ace, "/" ) >
												<cfset teacherList = listAppend( teacherList, rs_course.tch_name_ace, "/" ) />
											</cfif>
											
											<cfset wk1 = listFirst( rs_course.task_week, "-" ) />
											<cfset wk2 = listLast( rs_course.task_week, "-" ) />
											
											<cfset structInsert(passArgs, "ES", rs_course.es_id, true) />
											<cfset structInsert(passArgs, "SCC", rs_course.scc_id, true) />
											<cfset structInsert(passArgs, "TSK", rs_course.task_id, true) />
											<cfset structInsert(passArgs, "TT", rs_course.task_type, true) />
											
											<cfset sign = encrypt( rs_course.es_id & rs_course.scc_id & rs_course.task_type & rs_course.task_id, studentId, "PBEWithMD5AndDES", "Hex" ) />
											<cfset structInsert( passArgs, "ST", sign, true ) />

											<tr class="editRows">
												<td class="index"><cfoutput>#row#</cfoutput></td>
												<td><cfoutput>#rs_course.institute_short#</cfoutput></td>
												<td><cfoutput>#rs_course.course_name#</cfoutput><span class="numeric"> - </span><cfoutput>#teacherList#</cfoutput></td>
												<td><span class="numeric"><cfoutput>#numberFormat( rs_course.course_credit, "_.__" )#</cfoutput></span></td>
												<td><span class="numeric"><cfoutput>#rs_course.task_week#</cfoutput></span></td>
												<td>
													<cfif rs_course.state eq "NO" >
														
														<!--- 只有课程进行了两周后 才允许评教 --->
														<cfset writeLog( text=currentWeek ) />
														<cfset writeLog( text=wk1 ) /> 
														
														<cfif currentWeek - wk1 gt 2 >
																<a class="stat info" title="网上评价" href="<cfoutput>#buildURL('evaluateResponse', passArgs)#</cfoutput>"></a>
															<cfelse>
																<span class="stat locked" title="课程需要在开课两周后才允许网上评价"></span>
														</cfif>
														
													</cfif>
													
													<!--- 两段式评教 --->
													<cfif rs_course.es_model eq "M2">
														
														<cfif rs_course.state eq "C1">
															
															<cfif currentWeek gt wk2>
																	<!--- 课程已进行完 可以继续第二段评教 --->
																	<a class="stat info" title="网上评价" href="<cfoutput>#buildURL('evaluateResponse', passArgs)#</cfoutput>"></a>
																<cfelse>
																	<!--- 第一阶段已完成 等待课程结束 --->
																	<span class="stat waiting" title="请等待课程结束后, 进行第二轮网上评教"></span>
															</cfif>
															
														</cfif>
														
													</cfif>
													
													
													
													<cfif rs_course.state eq "CP">
														<!--- 已完成 --->
														<span class="stat checked" title="评教已完成"></span>
													</cfif>
													
												</td>
											</tr>
										</cfloop>
									</tbody>
								</table>

								<cfelse>

								<div class="systemNotice">
									<h3>太棒了</h3>
									<p class="mln">看起来, 您已经完成了目前所有的问卷. 谢谢您花费宝贵的时间帮助我们收集教学质量数据.</p>
								</div>
								
							</cfif>
							
							
						<cfelse>
						
							<div class="systemNotice">
								<h3>不是评教时间</h3>
								<p class="mln">目前尚未开展网上课程评价工作, 谢谢您的关注</p>
							</div>
						
					</cfif>
					
				</div>
				
				<div id="Talking" class="tabContent">
					
					<div class="noticeBlock">
						<h3>师生互动</h3>
						<p><span class="img icon16x16 message"></span>下面列出的是目前与您相关的课程意见与建议, 如果教师进行了回复您在这里也可以看到.</p>
						<hr/>
					</div>
					
					<cfif rs_comment.recordCount>
							
							<div class="mailContainer">
		
								<cfset row = 0 />
								<cfloop query="rs_comment">
			
									<cfset row++ />

									<div data-hash="<cfoutput>#sign#</cfoutput>" data-msg="<cfoutput>#rs_comment.msg_id#</cfoutput>" class="mailBox">
						
										<div class="index"><i><cfoutput>#row#</cfoutput></i></div>
						
										<div class="box">

											<div class="main">
												<div class="header">
													<b>发送时间:</b> 
													<span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString( rs_comment.suggest_date, "YYYY-MM-DD" )#</cfoutput></span>
												</div>
												<div class="message">
													<b>◆</b>
													<div><cfoutput>#stringAdvice.HTMLEncode( rs_comment.suggest )#</cfoutput></div>
												</div>
								
												<cfif rs_comment.reply neq "NOPE" >
													<div class="reply">
														<span class="bot2"></span>
														<span class="top2"></span>  
														<div><cfoutput>#stringAdvice.HTMLEncode( rs_comment.reply )#</cfoutput></div>
													</div>
													<div class="footer">
														<b>回复时间:</b> 
														<span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString( rs_comment.reply_date, "YYYY-MM-DD" )#</cfoutput></span>
													</div>
												</cfif>
									
											</div>

										</div>
						
									</div>

								</cfloop>
	
							</div>
							
						<cfelse>
						
					</cfif>
					
				</div>
				
			</div>
		</li>
	</ul>
</div>

